package com.mycat.service.ucenter.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mycat.dao.entity.ucenter.Customer;
import com.mycat.dao.mapper.ucenter.CustomerMapper;
import com.mycat.service.ucenter.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService{

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public void save(Customer customer) {
        customer.setCreateDate(new Date());
        customerMapper.insertUseGeneratedKeys(customer);
    }

    @Override
    public void edit(Customer customer) {
        customer.setUpdateDate(new Date());
        customerMapper.updateByPrimaryKeySelective(customer);
    }

    @Override
    public void delete(Integer[] ids) {
        for (Integer id : ids) {
            customerMapper.deleteByPrimaryKey(id);
        }
    }

    @Override
    public Customer findCustomer(Integer id) {
        return  customerMapper.selectByPrimaryKey(id);
    }

    @Override
    public Customer findCustomer(Customer customer) {
        return customerMapper.selectCustomer(customer);
    }

    @Override
    public PageInfo<Customer> page(Page<Customer> page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        List<Customer>  datas =  customerMapper.selectAll();
        PageInfo<Customer> pageInfo = new PageInfo<>(datas);
        return pageInfo;
    }

}